#include <reg52.h>
#include <intrins.h>

#define uint unsigned int
#define uchar unsigned char

sbit dula = P2^6;
sbit wela = P2^7;

uchar temp, t, n;
uchar code table[]={
		0x3f,0x06,0x5b,0x4f,
		0x66,0x6d,0x7d,0x07,
		0x7f,0x6f };

void delay(uint k)
{
	uint i, j;
	for (j = k; j > 0; j--)
		for (i = k; i > 0; i--);
}

void main()
{
	TMOD = 0x01;
	TH0 = (65536 - 50000) / 256;
	TL0 = (65536 - 50000) % 256;
	EA = 1;
	ET0 = 1;
	TR0 = 1;
	temp = 0xfe;
	P1 = temp;
	
	t = 0;
	n = 0;
	
	wela = 1;
	P0 = 0xc0;
	wela = 0;
	
	dula = 1;
	P0 = 0x3f;
	dula = 0;
	
	while (1)
	{
		delay(200);
		temp = _crol_(temp, 1);
		P1 = temp;
	}
}

void timer0() interrupt 1
{
	TH0 = (65536 - 50000) / 256;
	TL0 = (65536 - 50000) % 256;
	t++;
	if (t == 40)
	{
		t = 0;
		n++;
		if (n == 10)
			n = 0;
		
		dula = 1;
		P0 = table[n];
		dula = 0;			
	}
}